package com.codeduck.properties.byFile;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.PropertiesFactoryBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * @auther Mahone Yan
 * @date 2023/5/5
 */
@Component
public class KafkaProducerProperties {

    public Properties getProducerProperties(Resource propertiesLocation) {
        Properties properties = new Properties();
        try {
            PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean();
            propertiesFactoryBean.setLocation(propertiesLocation);
            propertiesFactoryBean.afterPropertiesSet();
            properties = propertiesFactoryBean.getObject();
        } catch (IOException e) {
            // 处理读取属性文件出错的情况
            e.printStackTrace();
        }
        return properties;
    }
}
